package com.visualize.demo.service;

import com.visualize.demo.model.*;
import com.visualize.demo.repository.ThreeEmotionRepository;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ThreeEmotionService extends BaseService {
    private final ThreeEmotionRepository threeEmotionRepository;

    public ThreeEmotionService(ThreeEmotionRepository threeEmotionRepository) {
        this.threeEmotionRepository = threeEmotionRepository;
    }

    public JsonResponse getData(String sTime, String eTime) {
        List<ThreeEmotion> emotionList = threeEmotionRepository.getThreeEmotionsByTime(parseDate(sTime), parseDate(eTime));
        Map<String, List<ThreeEmotion>> content = new HashMap<>();
        content.put("list", emotionList);
        return new JsonResponse(200, content);
    }

    public JsonResponse getPercentData(String sTime, String eTime) {
        List<ThreeEmotion> emotionList = threeEmotionRepository.getThreeEmotionsByTime(parseDate(sTime), parseDate(eTime));
        List<ThreeEmotionPercent> list = new ArrayList<>();
        for (ThreeEmotion threeEmotion : emotionList) {
            list.add(new ThreeEmotionPercent(
                    threeEmotion.getGood(),
                    threeEmotion.getBad(),
                    threeEmotion.getMedium(),
                    threeEmotion.getTime()
            ));
        }
        Map<String, List<ThreeEmotionPercent>> content = new HashMap<>();
        content.put("list", list);
        return new JsonResponse(200, content);
    }
}
